<?php
/** begin cek session */
if (!$this->session->userdata("login"))
  redirect('sessions/login');

$menux = $this->auth->get_menu_new();

$root = $this->config->item("menu_root");
$active = $this->config->item("menu_active");

function menu($menu,$base,$child=0,$active="",$root=""){
	$html = "";
	$akhiran='';
	if($child == 1)
		$html .= "<ul class=\"sub-menu\">\n";
	foreach($menu as $row){
		$url='';
		if(strpos($row['url'],'http') === false){
			if($row['url'] != "#")
				$url = "$base$row[url]";
		}else{
			$url = $row['url'];
		}
		
		$is_parent = false;
		if(count($row['sub']) > 0)
			$is_parent = true;
			
		$html .= "<li ".(($active == $row['alias'] || $root == $row['alias'])?'class="active"':'').">\n";		
		$html .= "<a href='$url'>
					<i class=\"".($row['icon'] != ""?$row['icon']."":'icomoon-icon-arrow-right-2')."\"></i>
					<span class=\"title\">$row[name]</span>
					".($is_parent?'<span class="arrow"></span>':'')."
					".(($active == $row['alias'] || $root == $row['alias'])?'<span class="selected"></span>':'')."
				</a>\n";
		if($is_parent){
			$html .= "<ul class=\"sub-menu\">\n";
			
			foreach($row['sub'] as $child){
				
				$is_parent = false;
				if(count($child['sub']) > 0)
					$is_parent = true;
				
				if($child['url'] != "#")
					$url = "$base$child[url]";
					
				$html .= "<li ".(($active == $child['alias'] || $root == $child['alias'])?'class="active"':'').">\n";		
				$html .= "<a href='$url'>
							<i class=\"".($child['icon'] != ""?$child['icon']."":'icomoon-icon-arrow-right-2')."\"></i>
							<span class=\"title\">$child[name]</span>
							".($is_parent?'<span class="arrow"></span>':'')."
						</a>\n";
				if($is_parent){
					$html .= menu($child['sub'],$base,1,$active,$root);
				}
				$html .= "</li>\n";
			}
			$html .= "</ul>\n";
				
		}
		$html .= "</li>\n";
	}
	
	if($child == 1)
		$html .= "</ul>\n";
		
	return $html;
}

?>
<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">
<html xmlns="http://www.w3.org/1999/xhtml">
<?php echo $header?>

<!-- BEGIN BODY -->
<body class="fixed-top">
   <!-- BEGIN HEADER -->
   <div class="header navbar navbar-inverse navbar-fixed-top">
      <!-- BEGIN TOP NAVIGATION BAR -->
      <div class="navbar-inner">
         <div class="container-fluid">
            <!-- BEGIN LOGO -->
            <a class="brand" href="<?php echo base_url()?>">
           <?php /* <img src="<?php echo base_url()?>template/img/logo.png" alt="logo" /> */?>
            </a>
            <!-- END LOGO -->
            <!-- BEGIN RESPONSIVE MENU TOGGLER -->
            <a href="javascript:;" class="btn-navbar collapsed" data-toggle="collapse" data-target=".nav-collapse">
            <img src="<?php echo base_url()?>template/img/menu-toggler.png" alt="" />
            </a>          
            <!-- END RESPONSIVE MENU TOGGLER -->            
            <!-- BEGIN TOP NAVIGATION MENU -->
			
            <ul class="nav pull-right">
				<?php /*
               <!-- BEGIN NOTIFICATION DROPDOWN -->   
               <li class="dropdown" id="header_notification_bar">
                  <a href="#" class="dropdown-toggle" data-toggle="dropdown">
                  <i class="icon-warning-sign"></i>
                  <span class="badge">6</span>
                  </a>
                  <ul class="dropdown-menu extended notification">
                     <li>
                        <p>You have 14 new notifications</p>
                     </li>
                     <li>
                        <a href="#">
                        <span class="label label-success"><i class="icon-plus"></i></span>
                        New user registered. 
                        <span class="time">Just now</span>
                        </a>
                     </li>
                     <li>
                        <a href="#">
                        <span class="label label-important"><i class="icon-bolt"></i></span>
                        Server #12 overloaded. 
                        <span class="time">15 mins</span>
                        </a>
                     </li>
                     <li>
                        <a href="#">
                        <span class="label label-warning"><i class="icon-bell"></i></span>
                        Server #2 not respoding.
                        <span class="time">22 mins</span>
                        </a>
                     </li>
                     <li>
                        <a href="#">
                        <span class="label label-info"><i class="icon-bullhorn"></i></span>
                        Application error.
                        <span class="time">40 mins</span>
                        </a>
                     </li>
                     <li>
                        <a href="#">
                        <span class="label label-important"><i class="icon-bolt"></i></span>
                        Database overloaded 68%. 
                        <span class="time">2 hrs</span>
                        </a>
                     </li>
                     <li>
                        <a href="#">
                        <span class="label label-important"><i class="icon-bolt"></i></span>
                        2 user IP blocked.
                        <span class="time">5 hrs</span>
                        </a>
                     </li>
                     <li class="external">
                        <a href="#">See all notifications <i class="m-icon-swapright"></i></a>
                     </li>
                  </ul>
               </li>
			   */?>
               <!-- END NOTIFICATION DROPDOWN -->
               <!-- BEGIN USER LOGIN DROPDOWN -->
               <li class="dropdown user">
                  <a href="#" class="dropdown-toggle" data-toggle="dropdown">
                  <img alt="" src="<?php echo base_url()?>template/img/avatar.png" width="29" height="29" />
                  <span class="username"><?php echo $this->session->userdata("nama")?></span>
                  <i class="icon-angle-down"></i>
                  </a>
                  <ul class="dropdown-menu">
                     <li><a href="<?php echo base_url()?>user"><i class="icon-user"></i> Pengaturan Akun</a></li>
                     <li><a href="<?php echo base_url()?>sessions/logout"><i class="icon-key"></i> Keluar</a></li>
                  </ul>
               </li>
               <!-- END USER LOGIN DROPDOWN -->
            </ul>
            <!-- END TOP NAVIGATION MENU --> 
         </div>
      </div>
      <!-- END TOP NAVIGATION BAR -->
   </div>
   <!-- END HEADER -->
   
   <!-- BEGIN CONTAINER -->
   <div class="page-container">
      <!-- BEGIN SIDEBAR -->
      <div class="page-sidebar nav-collapse collapse">
         <!-- BEGIN SIDEBAR MENU -->        	
			<ul>
				<li>
					<!-- BEGIN SIDEBAR TOGGLER BUTTON -->
					<div class="sidebar-toggler hidden-phone"></div>
					<!-- BEGIN SIDEBAR TOGGLER BUTTON -->
				</li>
				<li>
					<!-- BEGIN RESPONSIVE QUICK SEARCH FORM -->
					<form class="sidebar-search">
						<div class="input-box">
							
						</div>
					</form>
					<!-- END RESPONSIVE QUICK SEARCH FORM -->
				</li>
				
                <?php echo menu($menux,base_url(),0,$active,$root)?>  
			</ul>
		<!-- END SIDEBAR MENU -->
      </div>
      <!-- END SIDEBAR -->
   <?php echo $content ?>
   
   </div>
   <!-- END CONTAINER -->
   
   <?php echo $footer ?>
</body>
<!-- END BODY -->
</html>
